# -*- coding:utf-8 -*-
import json
import os

# 读取json文件
with open(os.path.join(os.path.dirname(__file__),'china.json'),'r',encoding='utf-8') as  f:
    china_list=json.loads(f.read())['zpData']

province_dict,city_dict={},{}

for province in china_list['cityList']:

    province_dict[province['name']]=province['code']

    for city in province['subLevelModelList']:
        city_dict[city['name']]=city['code']

with open(os.path.join(os.path.dirname(__file__),'province.json'),'w',encoding='utf-8') as  f:
    f.write(str(province_dict).replace('\'','"'))

with open(os.path.join(os.path.dirname(__file__),'city.json'),'w',encoding='utf-8') as  f:
    f.write(str(city_dict).replace('\'','"'))

print('处理完成！')